home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / OpenGL / space / light.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.1 KB  |  158 lines

  1. /*
  2.  * Copyright (C) 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "space.h"
  18.  
  19. #ifdef SP_IRIS_GL
  20. static flot32 planet_material[] = {
  21.     AMBIENT,   0.08, 0.08, 0.08,
  22.     DIFFUSE,   1.00, 1.00, 1.00,
  23.     SPECULAR,  0.00, 0.00, 0.00,
  24.     SHININESS, 0.00,
  25.     LMNULL
  26. };
  27.  
  28. static flot32 infinite_viewer[] = {
  29.     AMBIENT, 0.08,  0.08, 0.08,
  30.     LOCALVIEWER, 0.0,
  31.     LMNULL
  32. };
  33.  
  34. static flot32 infinite_light[] = {
  35.     AMBIENT,  0.08, 0.08, 0.08,
  36.     LCOLOR,   1.00, 1.00, 1.00,
  37.     POSITION, 0.00, 0.00, -1.00, 0.00,
  38.     LMNULL
  39. };
  40. #endif
  41.  
  42. #ifdef SP_OPEN_GL
  43. static flot32 mat_emi[] = { 0.00, 0.00, 0.00, 0.00 };
  44. static flot32 mat_amb[] = { 0.08, 0.08, 0.08, 1.00 };
  45. static flot32 mat_dif[] = { 1.00, 1.00, 1.00, 1.00 };
  46. static flot32 mat_spe[] = { 0.00, 0.00, 0.00, 1.00 };
  47. static flot32 mat_shi[] = { 0.00 };
  48.  
  49. static flot32 mod_amb[] = { 0.08, 0.08, 0.08, 1.00 };
  50. static flot32 mod_loc[] = { 0.00 };
  51. static flot32 mod_two[] = { 0.00 };
  52.  
  53. static flot32 lig_amb[] = { 0.08, 0.08, 0.08, 1.00 };
  54. static flot32 lig_dif[] = { 1.00, 1.00, 1.00, 1.00 };
  55. static flot32 lig_spe[] = { 0.00, 0.00, 0.00, 1.00 };
  56. static flot32 lig_pos[] = { 0.00, 0.00,-1.00, 0.00 };
  57. #endif
  58.  
  59. /********************************************************************** 
  60. *  spInitLight()  -  
  61. **********************************************************************/
  62. void spInitLight(void)
  63.  
  64. {
  65. #ifdef SP_IRIS_GL
  66.    lmdef(DEFMATERIAL, 1, 0, planet_material);
  67.    lmbind(MATERIAL,  0);
  68.  
  69.    lmdef(DEFLMODEL,   1, 0, infinite_viewer);
  70.    lmbind(LMODEL,  1);
  71. #endif
  72.  
  73. #ifdef SP_OPEN_GL
  74.    glMaterialfv(GL_FRONT,GL_EMISSION,mat_emi);
  75.    glMaterialfv(GL_FRONT,GL_AMBIENT,mat_amb);
  76.    glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_dif);
  77.    glMaterialfv(GL_FRONT,GL_SPECULAR,mat_spe);
  78.    glMaterialfv(GL_FRONT,GL_SHININESS,mat_shi);
  79.  
  80.    glLightModelfv(GL_LIGHT_MODEL_AMBIENT,mod_amb);
  81.    glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER,mod_loc);
  82.    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,mod_two);
  83.  
  84.    glLightfv(GL_LIGHT0,GL_AMBIENT,lig_amb);
  85.    glLightfv(GL_LIGHT0,GL_DIFFUSE,lig_dif);
  86.    glLightfv(GL_LIGHT0,GL_SPECULAR,lig_spe);
  87.    glLightfv(GL_LIGHT0,GL_POSITION,lig_pos);
  88.  
  89.    glEnable(GL_LIGHT0);
  90. #endif
  91. }
  92.  
  93. /********************************************************************** 
  94. *  spSetLight()  -  
  95. **********************************************************************/
  96. void spSetLight(V3 *vec)
  97.  
  98. {
  99. #ifdef SP_IRIS_GL
  100.    infinite_light[ 9] = vec->x;
  101.    infinite_light[10] = vec->y;
  102.    infinite_light[11] = vec->z;
  103.  
  104.    lmdef(DEFLIGHT,1,0,infinite_light);
  105.    lmbind(LIGHT1,  1);
  106. #endif
  107.  
  108. #ifdef SP_OPEN_GL
  109.    flot32 arr[4];
  110.  
  111.    arr[0] = vec->x;
  112.    arr[1] = vec->y;
  113.    arr[2] = vec->z;
  114.    arr[3] = 0.0;
  115.    glLightfv(GL_LIGHT0,GL_POSITION,arr);
  116. #endif
  117. }
  118.  
  119. /********************************************************************** 
  120. *  spLightMaterial()  -  
  121. **********************************************************************/
  122. void spLightMaterial(uint32 flag,uint32 col)
  123.  
  124. {
  125. #ifdef SP_IRIS_GL
  126.    if (flag) {
  127.      lmbind(MATERIAL,1);
  128.      lmcolor(LMC_DIFFUSE) ;
  129.      cpack(col);
  130.      }
  131.    else {
  132.      lmbind(MATERIAL,0);
  133.      lmcolor(LMC_COLOR) ;
  134.      cpack(col);
  135.      }
  136. #endif
  137.  
  138. #ifdef SP_OPEN_GL
  139.    flot32 arr[4];
  140.  
  141.    if (flag) {
  142.      glEnable(GL_LIGHTING);
  143.      glEnable(GL_NORMALIZE) ;
  144.  
  145.      arr[0] = ((col >>  0) & 0xff)/255.0;
  146.      arr[1] = ((col >>  8) & 0xff)/255.0;
  147.      arr[2] = ((col >> 16) & 0xff)/255.0;
  148.      arr[3] = ((col >> 24) & 0xff)/255.0;
  149.      glMaterialfv(GL_FRONT,GL_DIFFUSE,arr) ;
  150.      }
  151.    else {
  152.      glDisable(GL_LIGHTING);
  153.      glDisable(GL_NORMALIZE) ;
  154.      }
  155. #endif
  156. }
  157.  
  158.